#!/bin/bash

#配置字段
MYSQL_CONTAINER=mysql8
USERNAME=用户名
PORT=3306
PASSWORD='密码'
LOG_FILE=/docker/mysql/clusterReboot.log
WAIT_SECOND=10


bootMsg="=========\n=========\n准备重启集群=$(date "+%Y-%m-%d %H:%M:%S") \n等待$WAIT_SECOND秒"
echo -e $bootMsg
echo -e $bootMsg>>$LOG_FILE
sleep $WAIT_SECOND

# 使用docker exec 进入MySQLShell并执行命令
# 注意 rebootClusterFromCompleteOutage可能要持续1分钟...
docker exec -i $MYSQL_CONTAINER mysqlsh --uri="$USERNAME@localhost:$PORT" --password=$PASSWORD --js <<- EOF >> $LOG_FILE 2>&1
    print('准备重启集群='+new Date()+'\n');
    dba.rebootClusterFromCompleteOutage();
    dba.getCluster().status();
EOF

bootMsgEd="执行完毕=$(date "+%Y-%m-%d %H:%M:%S")"
echo -e $bootMsgEd>>$LOG_FILE
echo -e $bootMsgEd

exit 0